package com.huike.stock_analysis.controller;


import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.service.ProfitService;





/**
 * 
 * @author mzLEI
 * 盈利能力接口
 */
@RestController
@CrossOrigin(value = "*")
@RequestMapping("/profit")
public class ProfitController {
	@Autowired
	private ProfitService pService;
	
	//营业利润率
	@RequestMapping("/profitRatio")
	public String profitRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = pService.profitRatio(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	
	//净资产收益率
	@RequestMapping("/netAssetsIncomRatio")
	public String netAssetsIncomRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = pService.netAssetsIncomRatio(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//每股收益
	@RequestMapping("/perShareProfit")
	public String perShareProfit(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = pService.perShareProfit(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//主营业务收入//和行业平均
	@RequestMapping("/mainBusinessIncome")
	public String mainBusinessIncome(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = pService.mainBusinessIncome(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//净利润和行业平均
	@RequestMapping("/netProfit")
	public String netProfit(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = pService.netProfit(stock);
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//销售毛利率
	@RequestMapping("/grossProfitRatio")
	public String grossProfitRatio(String stock) {
		if(stock == null) return "null";
		
		return pService.grossProfitRatio(stock);
	}
	
	//销售净利率
	@RequestMapping("/grossNetProfitRatio")
	public String grossNetProfitRatio(String stock) {
		if(stock == null) return "null";
		return pService.grossNetProfitRatio(stock);
	}
	
	//成本费用利润率
	@RequestMapping("/costProfitRatio")
	public String costProfitRatio(String stock) {
		if(stock == null) return "null";
		return pService.costProfitRatio(stock);
	}
	
	
	
	//盈余现金保障倍数
	@RequestMapping("/leftCashTimes")
	public String leftCashTimes(String stock) {
		if(stock == null) return "null";
		return pService.leftCashTime(stock);
	}
	/*
	//每股净资产
	@RequestMapping("/perNetAssets")
	public String perNetAssets() {
		Map<String, String> map = pService.perNetAssets();
		ObjectMapper mapper = new ObjectMapper();
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	*/
}

